package com.bluerox.updating;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class Test {
	public static void main(String[] args) {
		Entity e = new Entity();
		e.setTitle("race");
		e.setVersion("1.0.0");
		e.setBaseUrl("http://localhost:8080/race/race1.0.0/");//BaseUrl的构造方式
		e.setBasePath("/home/lijianbo/test");
		
		/*//压缩文件
		Zip zip = new Zip();
		//压缩文件的路径
		String zipSourcePath = "/home/lijianbo/testSourceFiles/race";
		//压缩后文件的存放路径
		String zipFilePath = "/var/lib/tomcat6/webapps/ROOT/race/race1.0.0/level1";
		zip.zipAllFile(zipSourcePath, zipFilePath);
		*/
		
		XML xml = new XML(e);
		/*
		//生成状态文件
		//资源文件地址
		String sourcePath = "/var/lib/tomcat6/webapps/ROOT/race/race1.0.0/level1";
		//存放xml文件的地址
		String destPath = "/var/lib/tomcat6/webapps/ROOT/race/race1.0.0/";
		//级别值
		String levelValue = "1";
		//xml文件名
		String xmlName = "status.xml";
		xml.buildStatusFile(sourcePath, destPath, levelValue, xmlName);
		*/
		
		//生成索引文件
		
		/*
		//1.生成最基本的索引文件
		String destPath = "/var/lib/tomcat6/webapps/ROOT/race/race1.0.0/";
		int maxLevel = 1;
		String mainFileName = "race_level_1.xml";
		//xml.buildBaseMainFile(destPath, maxLevel, mainFileName);
		*/
		
		//2.生成完全的索引文件
		String rootPath = "/home/lijianbo/testSourceFiles/race";
		String mainFilePath = "/var/lib/tomcat6/webapps/ROOT/race/race1.0.0/race_level_1.xml";
		Element element = null;
		Document doc = XML.parseFile(mainFilePath);
		element = doc.getRootElement().getChild("root");
		//element = doc.getRootElement().getChild("root").addContent(new Element("directory").setAttribute("name","test"));
		
		xml.buildMainFile(rootPath, mainFilePath, element);
		
	}
	

}
